package com.xxx.mybaitis;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * 模拟数据库连接池
 */
public class Connections {
	
	public static Connection getConnection(Configuration configuration) {
		Connection connection = null;
		
		try {
			// 加载数据库驱动
			Class.forName(configuration.getDriver());
			// 从驱动管理器里获取一个连接
			connection = DriverManager.getConnection(
							configuration.getUrl(), // url
							configuration.getUsername(), // username
							configuration.getPassword()); // password
		} catch (ClassNotFoundException | SQLException e) {
			e.printStackTrace();
		}
		
		return connection;
	}

}
